#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
yarn type:check:all
yarn find-unused-code:js

# This automatically builds Reanimated Babel plugin JavaScript files if their
# TypeScript counterparts were changed. It also adds the output file to the commit
# if the built file differs from currently committed one.
! git diff-index HEAD --name-only |\
grep -E '^plugin/' > /dev/null
if [ $? -eq 1 ]; then
  yarn plugin
  ! git status -u |\
  grep -E 'plugin/build/plugin\.js' > /dev/null
  if [ $? -eq 1 ]; then
    git add plugin/build/plugin.js
    echo "[Reanimated] Plugin files were automatically built and changes were spotted.\
    \n             Those changes were added to the commit." >&2
  fi
fi
